<template>
  <div id="dialogAddEdit">
    <el-dialog
      class="about-set"
      title="添加机审评论/内容风险词"
      :visible.sync="dialogData.isShow"
      width="450px"
      :before-close="labelHandleClose"
    >
      <div class="form-box">
        <el-form
          ref="ruleForm"
          :model="ruleForm"
          :rules="rules"
          label-width="170px"
          class="demo-ruleForm"
          @submit.native.prevent
        >
          <el-form-item label="机审评论/内容风险词：" prop="word">
            <el-input v-model.trim="ruleForm.word" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" plain @click="cancelLabel">取 消</el-button>
        <el-button
          type="success"
          :loading="loading"
          @click="confirmLabel('ruleForm')"
          >确认</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { addPosts } from '@/api/dangerWords/contentDangerWords' // 接口
export default {
  name: 'DialogAddEdit',
  msg: '内容/评论/回复高危词-新增弹窗',
  props: ['dialogData'],
  data() {
    return {
      loading: false,
      ruleForm: {
        word: '' // 严禁词
      },
      rules: {
        word: [
          { required: true, message: '高危词不能为空' },
          { min: 2, max: 20, message: '长度在 2 到 20 位', trigger: 'blur' }
        ]
      }
    }
  },
  mounted() {},
  methods: {
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    },
    cancelLabel() {
      // 关闭前清空
      this.loading = false
      this.dialogData.isShow = false
    },
    /* 确认提交 */
    confirmLabel(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          let obj = { ...this.ruleForm }
          let params = this.changeToForm(obj)
          addPosts(
            obj,
            (response) => {
              this.loading = false
              this.$emit('refresh')
              this.cancelLabel()
            },
            (response) => {
              this.loading = false
              this.$message({
                message: '新增失败，' + response.message,
                type: 'warning'
              })
            }
          )
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="less">
// #dialogAddEdit {
// }
</style>
